package com.ccb.sc.common.modules.ad.service.impl;

import com.ccb.sc.common.enums.ValidStatus;
import com.ccb.sc.common.modules.ad.service.IAdPositionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ccb.sc.common.modules.ad.entity.AdPosition;
import com.ccb.sc.common.modules.ad.mapper.AdPositionMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 广告位 服务实现类
 * </p>
 *
 * @author ken
 * @since 2020-10-05
 */
@Service
public class AdPositionServiceImpl extends ServiceImpl<AdPositionMapper, AdPosition> implements IAdPositionService {

//    @Override
//    public AdPosition findByCode(String code) {
//        return this.getOne(new QueryWrapper<AdPosition>()
//                .lambda()
//                .eq(AdPosition::getCode, code)
//                .orderByDesc(AdPosition::getCreateTime)
//                .last("limit 1"));
//    }

    @Override
    public AdPosition findByCode(String code) {
        AdPosition adPosition = this.getOne(new QueryWrapper<AdPosition>()
                .lambda()
                .eq(AdPosition::getCode, code)
                .orderByDesc(AdPosition::getCreateTime)
                .last("limit 1"));

//        if (adPosition != null) {
//            // 将整数值转换为 ValidStatus 枚举
//            int statusValue = adPosition.getStatus().getValue();
//            ValidStatus status = ValidStatus.getByValue(statusValue);
//            if (status == null) {
//                throw new IllegalArgumentException("Invalid status value: " + statusValue);
//            }
//            adPosition.setStatus(status);
//        }

        return adPosition;
    }
}
